/*
 * Copyright kecp
 * Jun 02, 2010
 */

package Gui;

import LBS.AddressSrv;
import LBS.Cell;
import LBS.GoogleMap;
import LBS.Location;
import Tool.Debugger;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import traveller.Assistant;
import traveller.TravelListener;

/**
 * 程序入口及主界面
 * @author kecp
 */
public class MainMIDlet extends MIDlet implements CommandListener , TravelListener,ItemCommandListener{

    private boolean midletPaused = false;
    private MapView mapView = null;
    private AddressSearch addrSearchView = null;
    Cell cell = new Cell();
    Location loct;
    AddressSrv addrSrv = null;
    Assistant assist;


    private Command stopWatchCmd = new Command("关闭提醒", Command.ITEM, 1);

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Command exitCommand;
    private Command getCellInfo;
    private Command backCommand;
    private Command itemCommand;
    private Command getLocation;
    private Command searchCmd;
    private Command back;
    private Command search;
    private Command mapCommand;
    private Command flashCmd;
    private Command logCommand;
    private Command watchCommand;
    private Command backCommand1;
    private Command cleanCommand;
    private Form MainForm;
    private StringItem myLocation;
    private StringItem destLocation;
    private StringItem distance;
    private Form CellInfoForm;
    private StringItem item_mnc;
    private StringItem item_mcc;
    private StringItem item_cellId;
    private StringItem item_lac;
    private TextBox logTextBox;
    private Ticker ticker;
    //</editor-fold>//GEN-END:|fields|0|


private String S40_cell_id;   // Series 40 cell id property
private String S60_cell_id;   // S60 cell id property
    /**
     * The MainMIDlet constructor.
     */
    public MainMIDlet() {
 //       cell.updateCellInfo();
        assist = Assistant.getTheAssistant();
        assist.setTravelListener(this);

        //创建文本字段
        getMyLocation();
        getDestLocation();
        getDistance();

        updateLocation();
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getMainForm());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|


  

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == CellInfoForm) {//GEN-BEGIN:|7-commandAction|1|31-preAction
            if (command == backCommand) {//GEN-END:|7-commandAction|1|31-preAction
                // write pre-action user code here
                switchDisplayable(null, getMainForm());//GEN-LINE:|7-commandAction|2|31-postAction
                // write post-action user code here
            } else if (command == flashCmd) {//GEN-LINE:|7-commandAction|3|59-preAction
                // write pre-action user code here
                cell.updateNetworkInfo();
                updateCellIdForm();
//GEN-LINE:|7-commandAction|4|59-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|5|19-preAction
        } else if (displayable == MainForm) {
            if (command == exitCommand) {//GEN-END:|7-commandAction|5|19-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|6|19-postAction
                // write post-action user code here
            } else if (command == getCellInfo) {//GEN-LINE:|7-commandAction|7|27-preAction
                // write pre-action user code here
                updateCellIdForm();
                switchDisplayable(null, getCellInfoForm());//GEN-LINE:|7-commandAction|8|27-postAction
                // write post-action user code here
            } else if (command == getLocation) {//GEN-LINE:|7-commandAction|9|42-preAction
                // write pre-action user code here
                assist.updateCurLoct();
//GEN-LINE:|7-commandAction|10|42-postAction
                // write post-action user code here
            } else if (command == logCommand) {//GEN-LINE:|7-commandAction|11|63-preAction
                // write pre-action user code here
                updateLogForm();
                switchDisplayable(null, getLogTextBox());//GEN-LINE:|7-commandAction|12|63-postAction
                // write post-action user code here

            } else if (command == mapCommand) {//GEN-LINE:|7-commandAction|13|54-preAction
                // write pre-action user code here
                if( mapView == null )
                    mapView = new MapView(this);
                mapView.switchDisplayable(null, mapView.getMapForm());
//GEN-LINE:|7-commandAction|14|54-postAction
                // write post-action user code here
            } else if (command == search) {//GEN-LINE:|7-commandAction|15|49-preAction
                // write pre-action user code here
                if( addrSearchView == null )
                    addrSearchView = new AddressSearch(this);
                addrSearchView.switchDisplayable(null, addrSearchView.getAddressForm());
//GEN-LINE:|7-commandAction|16|49-postAction
                // write post-action user code here
            } else if (command == watchCommand) {//GEN-LINE:|7-commandAction|17|61-preAction
                // write pre-action user code here
                assist.beginWatch();
                getMainForm().removeCommand(watchCommand);
                getMainForm().addCommand(stopWatchCmd);
//GEN-LINE:|7-commandAction|18|61-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|72-preAction
        } else if (displayable == logTextBox) {
            if (command == cleanCommand) {//GEN-END:|7-commandAction|19|72-preAction
                // write pre-action user code here
                Debugger.cleanLog();
                updateLogForm();
//GEN-LINE:|7-commandAction|20|72-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|21|7-postCommandAction
        }//GEN-END:|7-commandAction|21|7-postCommandAction
        // write post-action user code here
        if (displayable == MainForm) {
             if (command == stopWatchCmd) {
                // write pre-action user code here
                assist.stopWatch();
                getMainForm().removeCommand(stopWatchCmd);
                getMainForm().addCommand(watchCommand);
             }
        }
        if (displayable == logTextBox) {

            if (command == backCommand) {

                // write pre-action user code here
                switchDisplayable(null, getMainForm());
                // write post-action user code here
            }
        }
    }//GEN-BEGIN:|7-commandAction|22|
    //</editor-fold>//GEN-END:|7-commandAction|22|




    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            exitCommand = new Command("\u9000\u51FA", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|18-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: MainForm ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of MainForm component.
     * @return the initialized component instance
     */
    public Form getMainForm() {
        if (MainForm == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            MainForm = new Form("\u65C5\u6E38\u52A9\u624B", new Item[] { getMyLocation(), getDestLocation(), getDistance() });//GEN-BEGIN:|14-getter|1|14-postInit
            MainForm.addCommand(getExitCommand());
            MainForm.addCommand(getGetCellInfo());
            MainForm.addCommand(getGetLocation());
            MainForm.addCommand(getSearch());
            MainForm.addCommand(getMapCommand());
            MainForm.addCommand(getWatchCommand());
            MainForm.addCommand(getLogCommand());
            MainForm.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return MainForm;
    }
    //</editor-fold>//GEN-END:|14-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: myLocation ">//GEN-BEGIN:|16-getter|0|16-preInit
    /**
     * Returns an initiliazed instance of myLocation component.
     * @return the initialized component instance
     */
    public StringItem getMyLocation() {
        if (myLocation == null) {//GEN-END:|16-getter|0|16-preInit
            // write pre-init user code here
            myLocation = new StringItem("\u6211\u7684\u4F4D\u7F6E", "");//GEN-BEGIN:|16-getter|1|16-postInit
            myLocation.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_BEFORE);//GEN-END:|16-getter|1|16-postInit
            // write post-init user code here

      //      myLocation.setDefaultCommand(getGetLocation());
      //      myLocation.setItemCommandListener(this);
        }//GEN-BEGIN:|16-getter|2|
        return myLocation;
    }
    //</editor-fold>//GEN-END:|16-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: getCellInfo ">//GEN-BEGIN:|26-getter|0|26-preInit
    /**
     * Returns an initiliazed instance of getCellInfo component.
     * @return the initialized component instance
     */
    public Command getGetCellInfo() {
        if (getCellInfo == null) {//GEN-END:|26-getter|0|26-preInit
            // write pre-init user code here
            getCellInfo = new Command("\u7F51\u7EDC\u4FE1\u606F", Command.ITEM, 0);//GEN-LINE:|26-getter|1|26-postInit
            // write post-init user code here
        }//GEN-BEGIN:|26-getter|2|
        return getCellInfo;
    }
    //</editor-fold>//GEN-END:|26-getter|2|
    //</editor-fold>
    //</editor-fold>
    //</editor-fold>
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: CellInfoForm ">//GEN-BEGIN:|25-getter|0|25-preInit
    /**
     * Returns an initiliazed instance of CellInfoForm component.
     * @return the initialized component instance
     */
    public Form getCellInfoForm() {
        if (CellInfoForm == null) {//GEN-END:|25-getter|0|25-preInit
            // write pre-init user code here
            CellInfoForm = new Form("CellInfo", new Item[] { getItem_cellId(), getItem_mnc(), getItem_mcc(), getItem_lac() });//GEN-BEGIN:|25-getter|1|25-postInit
            CellInfoForm.addCommand(getBackCommand());
            CellInfoForm.addCommand(getFlashCmd());
            CellInfoForm.setCommandListener(this);//GEN-END:|25-getter|1|25-postInit
            // write post-init user code here
        }//GEN-BEGIN:|25-getter|2|
        return CellInfoForm;
    }
    //</editor-fold>//GEN-END:|25-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|30-getter|0|30-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|30-getter|0|30-preInit
            // write pre-init user code here
            backCommand = new Command("\u540E\u9000", Command.BACK, 0);//GEN-LINE:|30-getter|1|30-postInit
            // write post-init user code here
        }//GEN-BEGIN:|30-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|30-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of itemCommand component.
     * @return the initialized component instance
     */
    public Command getItemCommand() {
        if (itemCommand == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            itemCommand = new Command("\u9879", Command.ITEM, 0);//GEN-LINE:|34-getter|1|34-postInit
            // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return itemCommand;
    }
    //</editor-fold>//GEN-END:|34-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: item_cellId ">//GEN-BEGIN:|36-getter|0|36-preInit
    /**
     * Returns an initiliazed instance of item_cellId component.
     * @return the initialized component instance
     */
    public StringItem getItem_cellId() {
        if (item_cellId == null) {//GEN-END:|36-getter|0|36-preInit
            // write pre-init user code here
            item_cellId = new StringItem("Cell_id", null);//GEN-LINE:|36-getter|1|36-postInit
            // write post-init user code here
        }//GEN-BEGIN:|36-getter|2|
        return item_cellId;
    }
    //</editor-fold>//GEN-END:|36-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: item_mnc ">//GEN-BEGIN:|38-getter|0|38-preInit
    /**
     * Returns an initiliazed instance of item_mnc component.
     * @return the initialized component instance
     */
    public StringItem getItem_mnc() {
        if (item_mnc == null) {//GEN-END:|38-getter|0|38-preInit
            // write pre-init user code here
            item_mnc = new StringItem("mnc", null);//GEN-LINE:|38-getter|1|38-postInit
            // write post-init user code here
        }//GEN-BEGIN:|38-getter|2|
        return item_mnc;
    }
    //</editor-fold>//GEN-END:|38-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: item_mcc ">//GEN-BEGIN:|39-getter|0|39-preInit
    /**
     * Returns an initiliazed instance of item_mcc component.
     * @return the initialized component instance
     */
    public StringItem getItem_mcc() {
        if (item_mcc == null) {//GEN-END:|39-getter|0|39-preInit
            // write pre-init user code here
            item_mcc = new StringItem("mcc", null);//GEN-LINE:|39-getter|1|39-postInit
            // write post-init user code here
        }//GEN-BEGIN:|39-getter|2|
        return item_mcc;
    }
    //</editor-fold>//GEN-END:|39-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: item_lac ">//GEN-BEGIN:|40-getter|0|40-preInit
    /**
     * Returns an initiliazed instance of item_lac component.
     * @return the initialized component instance
     */
    public StringItem getItem_lac() {
        if (item_lac == null) {//GEN-END:|40-getter|0|40-preInit
            // write pre-init user code here
            item_lac = new StringItem("lac", null);//GEN-LINE:|40-getter|1|40-postInit
            // write post-init user code here
        }//GEN-BEGIN:|40-getter|2|
        return item_lac;
    }
    //</editor-fold>//GEN-END:|40-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: getLocation ">//GEN-BEGIN:|41-getter|0|41-preInit
    /**
     * Returns an initiliazed instance of getLocation component.
     * @return the initialized component instance
     */
    public Command getGetLocation() {
        if (getLocation == null) {//GEN-END:|41-getter|0|41-preInit
            // write pre-init user code here
            getLocation = new Command("\u6211\u7684\u4F4D\u7F6E", Command.ITEM, 0);//GEN-LINE:|41-getter|1|41-postInit
            // write post-init user code here
        }//GEN-BEGIN:|41-getter|2|
        return getLocation;
    }
    //</editor-fold>//GEN-END:|41-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: searchCmd ">//GEN-BEGIN:|46-getter|0|46-preInit
    /**
     * Returns an initiliazed instance of searchCmd component.
     * @return the initialized component instance
     */
    public Command getSearchCmd() {
        if (searchCmd == null) {//GEN-END:|46-getter|0|46-preInit
            // write pre-init user code here
            searchCmd = new Command("\u641C\u7D22", Command.SCREEN, 0);//GEN-LINE:|46-getter|1|46-postInit
            // write post-init user code here
        }//GEN-BEGIN:|46-getter|2|
        return searchCmd;
    }
    //</editor-fold>//GEN-END:|46-getter|2|


    //</editor-fold>


    //</editor-fold>
    //</editor-fold>



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: search ">//GEN-BEGIN:|48-getter|0|48-preInit
    /**
     * Returns an initiliazed instance of search component.
     * @return the initialized component instance
     */
    public Command getSearch() {
        if (search == null) {//GEN-END:|48-getter|0|48-preInit
            // write pre-init user code here
            search = new Command("\u641C\u7D22", Command.SCREEN, 0);//GEN-LINE:|48-getter|1|48-postInit
            // write post-init user code here
        }//GEN-BEGIN:|48-getter|2|
        return search;
    }
    //</editor-fold>//GEN-END:|48-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: back ">//GEN-BEGIN:|51-getter|0|51-preInit
    /**
     * Returns an initiliazed instance of back component.
     * @return the initialized component instance
     */
    public Command getBack() {
        if (back == null) {//GEN-END:|51-getter|0|51-preInit
            // write pre-init user code here
            back = new Command("\u540E\u9000", Command.BACK, 0);//GEN-LINE:|51-getter|1|51-postInit
            // write post-init user code here
        }//GEN-BEGIN:|51-getter|2|
        return back;
    }
    //</editor-fold>//GEN-END:|51-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: mapCommand ">//GEN-BEGIN:|53-getter|0|53-preInit
    /**
     * Returns an initiliazed instance of mapCommand component.
     * @return the initialized component instance
     */
    public Command getMapCommand() {
        if (mapCommand == null) {//GEN-END:|53-getter|0|53-preInit
            // write pre-init user code here
            mapCommand = new Command("\u5730\u56FE", Command.SCREEN, 0);//GEN-LINE:|53-getter|1|53-postInit
            // write post-init user code here
        }//GEN-BEGIN:|53-getter|2|
        return mapCommand;
    }
    //</editor-fold>//GEN-END:|53-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: destLocation ">//GEN-BEGIN:|55-getter|0|55-preInit
    /**
     * Returns an initiliazed instance of destLocation component.
     * @return the initialized component instance
     */
    public StringItem getDestLocation() {
        if (destLocation == null) {//GEN-END:|55-getter|0|55-preInit
            // write pre-init user code here
            destLocation = new StringItem("\u76EE\u7684\u5730", "");//GEN-BEGIN:|55-getter|1|55-postInit
            destLocation.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_BEFORE);//GEN-END:|55-getter|1|55-postInit
            // write post-init user code here

            destLocation.setDefaultCommand(getSearch());
            destLocation.setItemCommandListener(this);
        }//GEN-BEGIN:|55-getter|2|
        return destLocation;
    }
    //</editor-fold>//GEN-END:|55-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: distance ">//GEN-BEGIN:|56-getter|0|56-preInit
    /**
     * Returns an initiliazed instance of distance component.
     * @return the initialized component instance
     */
    public StringItem getDistance() {
        if (distance == null) {//GEN-END:|56-getter|0|56-preInit
            // write pre-init user code here
            distance = new StringItem("\u8DDD\u79BB", "");//GEN-LINE:|56-getter|1|56-postInit
            // write post-init user code here
        }//GEN-BEGIN:|56-getter|2|
        return distance;
    }
    //</editor-fold>//GEN-END:|56-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ticker ">//GEN-BEGIN:|57-getter|0|57-preInit
    /**
     * Returns an initiliazed instance of ticker component.
     * @return the initialized component instance
     */
    public Ticker getTicker() {
        if (ticker == null) {//GEN-END:|57-getter|0|57-preInit
            // write pre-init user code here
            ticker = new Ticker("\u522B\u7761\u8FC7\u7AD9\u4E86\u54E6");//GEN-LINE:|57-getter|1|57-postInit
            // write post-init user code here
        }//GEN-BEGIN:|57-getter|2|
        return ticker;
    }
    //</editor-fold>//GEN-END:|57-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: flashCmd ">//GEN-BEGIN:|58-getter|0|58-preInit
    /**
     * Returns an initiliazed instance of flashCmd component.
     * @return the initialized component instance
     */
    public Command getFlashCmd() {
        if (flashCmd == null) {//GEN-END:|58-getter|0|58-preInit
            // write pre-init user code here
            flashCmd = new Command("\u5237\u65B0", Command.SCREEN, 0);//GEN-LINE:|58-getter|1|58-postInit
            // write post-init user code here
        }//GEN-BEGIN:|58-getter|2|
        return flashCmd;
    }
    //</editor-fold>//GEN-END:|58-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: watchCommand ">//GEN-BEGIN:|60-getter|0|60-preInit
    /**
     * Returns an initiliazed instance of watchCommand component.
     * @return the initialized component instance
     */
    public Command getWatchCommand() {
        if (watchCommand == null) {//GEN-END:|60-getter|0|60-preInit
            // write pre-init user code here
            watchCommand = new Command("\u5F00\u542F\u63D0\u9192", Command.ITEM, 0);//GEN-LINE:|60-getter|1|60-postInit
            // write post-init user code here
        }//GEN-BEGIN:|60-getter|2|
        return watchCommand;
    }
    //</editor-fold>//GEN-END:|60-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: logCommand ">//GEN-BEGIN:|62-getter|0|62-preInit
    /**
     * Returns an initiliazed instance of logCommand component.
     * @return the initialized component instance
     */
    public Command getLogCommand() {
        if (logCommand == null) {//GEN-END:|62-getter|0|62-preInit
            // write pre-init user code here
            logCommand = new Command("\u65E5\u5FD7", Command.SCREEN, 0);//GEN-LINE:|62-getter|1|62-postInit
            // write post-init user code here
        }//GEN-BEGIN:|62-getter|2|
        return logCommand;
    }
    //</editor-fold>//GEN-END:|62-getter|2|






    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: logTextBox ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initiliazed instance of logTextBox component.
     * @return the initialized component instance
     */
    public TextBox getLogTextBox() {
        if (logTextBox == null) {//GEN-END:|69-getter|0|69-preInit
            // write pre-init user code here
            logTextBox = new TextBox("\u65E5\u5FD7", null, 100, TextField.ANY);//GEN-BEGIN:|69-getter|1|69-postInit
            logTextBox.addCommand(getCleanCommand());
            logTextBox.setCommandListener(this);//GEN-END:|69-getter|1|69-postInit
            // write post-init user code here
            logTextBox.addCommand(getBackCommand());
            logTextBox.setCommandListener(this);
            logTextBox.setMaxSize(10000);
        }//GEN-BEGIN:|69-getter|2|
        return logTextBox;
    }
    //</editor-fold>//GEN-END:|69-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|70-getter|0|70-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|70-getter|0|70-preInit
            // write pre-init user code here
            backCommand1 = new Command("\u540E\u9000", Command.BACK, 0);//GEN-LINE:|70-getter|1|70-postInit
            // write post-init user code here
        }//GEN-BEGIN:|70-getter|2|
        return backCommand1;
    }
    //</editor-fold>//GEN-END:|70-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cleanCommand ">//GEN-BEGIN:|71-getter|0|71-preInit
    /**
     * Returns an initiliazed instance of cleanCommand component.
     * @return the initialized component instance
     */
    public Command getCleanCommand() {
        if (cleanCommand == null) {//GEN-END:|71-getter|0|71-preInit
            // write pre-init user code here
            cleanCommand = new Command("\u6E05\u7A7A", Command.SCREEN, 0);//GEN-LINE:|71-getter|1|71-postInit
            // write post-init user code here
        }//GEN-BEGIN:|71-getter|2|
        return cleanCommand;
    }
    //</editor-fold>//GEN-END:|71-getter|2|
    //</editor-fold>



    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay () {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable (null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    void testCellLoc(){
          cell.updateNetworkInfo();
      //    MainForm.append(cell.getImg());
    }

    void testGoogleMap() {
        MainForm.append( GoogleMap.testGetImg());
    }

    void test () {
        AddressSrv.testAddressSrv();
        //testGoogleMap();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
            startMIDlet ();
        }
        midletPaused = false; 
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }

    public void updateCellIdForm(){
        getItem_cellId().setText(cell.cell_id);
        getItem_mnc().setText(cell.mnc);
        getItem_mcc().setText(cell.mcc);
        getItem_lac().setText(cell.lac);
    }

    public void back() {
        Displayable dis = null;
        Display.getDisplay(this).setCurrent(MainForm);
    }

    /**
     * 将旅行信息显示到文本区域中
     */
    public  void updateLocation() {
        String str;
        StringBuffer sb;
        str = assist.getCurLoct().getName();
        if( str != null )
            myLocation.setText( str );
        else {
            Location loc = assist.getCurLoct();
            sb = new StringBuffer();
            sb.append("lat:").append(loc.getLat()).append(";lon:").append(loc.getLon());
        }

        str = assist.getDestLoct().getName();
        if( str != null )
            destLocation.setText( str );
         else {
            Location loc = assist.getDestLoct();
            sb = null;
            sb = new StringBuffer();
            sb.append("lat:").append(loc.getLat()).append(";lon:").append(loc.getLon());
        }
        distance.setText(String.valueOf(assist.getDistance()));
    }

    public void destChanged(Location dest) {
        updateLocation();
    }

    public void curChanged(Location cur) {
        updateLocation();
    }

    public void commandAction(Command c, Item item) {

        if( item == destLocation ) {
            this.commandAction(c, MainForm);
        }
        else if ( item == myLocation ) {
            this.commandAction(c, MainForm);
        }
    }

    private void updateLogForm() {

        String log = Debugger.getLog();
        if( log != null ) {
            getLogTextBox().setString(log);
        }


    }
}

/**
 * 界面管理，前进后退功能
 * @author kecp
 */
 class ViewManage {
    Displayable  displayStack[] = new Displayable[6];
    private MIDlet midlet;
    int stackPoint = 0;
    int stackRear = 0;

    public ViewManage( MIDlet mid ) {
        midlet = mid;
    }

    public Displayable back() {
        Displayable dis = null;
        if( stackPoint >  0 ) {
            stackPoint--;
            dis = displayStack[stackPoint];
            Display.getDisplay(midlet).setCurrent(dis);
        }
        return dis;
    }
    public Displayable forword() {
        Displayable dis = null;
        if( stackPoint < stackRear ){
            stackPoint++;
            dis = displayStack[stackPoint];
            Display.getDisplay(midlet).setCurrent(dis);
        }
        return dis;
    }

    public void setCurDisplay( Displayable dispable ){
        byte i;
        if( stackRear + 1 >= displayStack.length ) {
         //   for( i=0;)
        }
    }


 }